#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=2000, maxm=2000, maxz=2000;

class Graph {
public:
  int n, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1], fa[maxn+1], ans[maxn+1], rice[maxn+1][maxz+1], dep[maxn+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void build(int o, int fa) {
    this->fa[o] = fa;
    dep[o] = dep[fa]+1;
    for (int i=ind[o]; i; i=link[i]) {
      if (to[i]!=fa) {
	build(to[i], o);
      }
    }
  }

  void addRice(int u, int v, int z) {
    if (dep[u]<dep[v]) {
      int temp;
      temp=dep[u], dep[u]=dep[v], dep[v]=temp;
    }

    for (; dep[fa[u]]>=dep[v]; u=fa[u]) {
      rice[u][z]++;
      if (rice[u][z]>rice[u][ans[u]] || (rice[u][z]==rice[u][ans[u]] && z<ans[u])) {
	ans[u] = z;
      }
    }
    if (u==v) {
      rice[u][z]++;
      if (rice[u][z]>rice[u][ans[u]] || (rice[u][z]==rice[u][ans[u]] && z<ans[u])) {
	ans[u] = z;
      }
      return;
    }
    for (; u!=v; u=fa[u], v=fa[v]) {
      rice[u][z]++;
      if (rice[u][z]>rice[u][ans[u]] || (rice[u][z]==rice[u][ans[u]] && z<ans[u])) {
	ans[u] = z;
      }
      rice[v][z]++;
      if (rice[v][z]>rice[v][ans[v]] || (rice[v][z]==rice[v][ans[v]] && z<ans[v])) {
	ans[v] = z;
      }
    }
    rice[u][z]++;
    if (rice[u][z]>rice[u][ans[u]] || (rice[u][z]==rice[u][ans[u]] && z<ans[u])) {
      ans[u] = z;
    }
  }
};

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2_bf.out", "w", stdout);
#endif

  static Graph g;
  int n, m;
  scanf("%d %d", &n, &m);
  g.n = n;
  for (int i=1; i<n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    g.addSide(a, b);
    g.addSide(b, a);
  }
  g.build(1, 0);
  for (int i=1; i<=m; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    g.addRice(x, y, z);
  }

  for (int i=1; i<=n; i++) {
    printf("%d\n", g.ans[i]);
  }

  fclose(stdin);
  fclose(stdout);
}
